/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef PLSTATICMEMHANDLER_H
#define PLSTATICMEMHANDLER_H

#include <machine/pc/memory/memhandlerinterface.h>

class PLStaticMemHandler : public PLMemHandlerInterface {
public:
	/**
	 * Constructor.
	 */
	PLStaticMemHandler();
	/**
	 * Set the start point for memory allocation.
	 */
	void init();
	/**
	 * Allocate memory with a size.
	 *
	 * @param size The size of the memory to allocate.
	 * @return Pointer to the memory.
	 */
	void *alloc(size_t size);
	/**
	 * Delete the allocated memory.
	 *
	 * @param mem The memory to delete.
	 */
	void dealloc(void *mem);
	/**
	 * Get the current position of the last used memory.
	 *
	 * @return The last position.
	 */
	inline uintptr_t currentMem();
	/**
	 * Align the memory to the pagesize.
	 *
	 * @param pageSize The new pagesize to align the current memory position to.
	 */
	void alignToPage(int pageSize);
	/**
	 * Get the size of a memory pointer.
	 *
	 * @param mem The memory pointer.
	 * @return The size.
	 */
	size_t sizeOfMem(void *mem);
private:
	uintptr_t m_startMem;
	uintptr_t m_currentMem;
};

uintptr_t PLStaticMemHandler::currentMem() {
	return m_currentMem;
}

#endif // PLSTATICMEMHANDLER_H
